package com.sc.nft.entity.vo;

import com.sc.nft.enums.MallProfitTemplateTypeEnum;
import com.sc.nft.exception.GlobalRunTimeException;
import com.sc.nft.util.BigDecimalUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.*;
import java.math.BigDecimal;
import java.util.List;

/**
 * 添加分润模版
 * @author liGen
 * @version 1.0
 * @date 2024/1/10 3:18 下午
 */
@Data
public class EditMallProfitTemplateVO {

    @ApiModelProperty("id 当编辑时必传")
    private Long id;

    @ApiModelProperty(value = "模版名称")
    @NotBlank(message = "请输入模版名称！")
    private String templateName;

    @ApiModelProperty(value = "模版类型")
    @NotNull(message = "请选择模版类型！")
    private MallProfitTemplateTypeEnum templateType;

    @ApiModelProperty(value = "直推收益比例")
    @NotNull(message = "请输入直推收益比例！")
    @DecimalMin(value = "0.00", message = "直推分润比例小于0.00")
    @DecimalMax(value = "1.00", message = "直推分润比例大于1.00")
    private BigDecimal directIncome;

    @ApiModelProperty(value = "关联藏品多选 藏品ID集合")
    private List<Long> collectionId;

    @ApiModelProperty(value = "供应商推荐人收益比例")
    @NotNull(message = "请输入供应商推荐人收益比例！")
    @DecimalMin(value = "0.00", message = "供应商推荐人分润比例小于0.00")
    @DecimalMax(value = "1.00", message = "供应商推荐人分润比例大于1.00")
    private BigDecimal supplierReferrerIncome;

    @ApiModelProperty(value = "地图省级收益比例")
    @NotNull(message = "请输入地图省级收益比例！")
    @DecimalMin(value = "0.00", message = "地图分润比例小于0.00")
    @DecimalMax(value = "1.00", message = "地图分润比例大于1.00")
    private BigDecimal mapIncome;

//    @ApiModelProperty(value = "地图市级收益比例")
//    @NotNull(message = "请输入地图市级收益比例！")
//    @DecimalMin(value = "0.00", message = "地图分润比例小于0.00")
//    @DecimalMax(value = "1.00", message = "地图分润比例大于1.00")
//    private BigDecimal mapCityIncome;
//
//    @ApiModelProperty(value = "地图区级收益比例")
//    @NotNull(message = "请输入地图区级收益比例！")
//    @DecimalMin(value = "0.00", message = "地图分润比例小于0.00")
//    @DecimalMax(value = "1.00", message = "地图分润比例大于1.00")
//    private BigDecimal mapRegionIncome;

    @ApiModelProperty(value = "城市服务中心收益比例")
    @NotNull(message = "请输入城市服务中心收益比例！")
    @DecimalMin(value = "0.00", message = "城市服务中心分润比例小于0.00")
    @DecimalMax(value = "1.00", message = "城市服务中心分润比例大于1.00")
    private BigDecimal urbanServiceCenterIncome;

    @ApiModelProperty(value = "社区工作室收益比例")
    @NotNull(message = "请输入社区工作室收益比例！")
    @DecimalMin(value = "0.00", message = "社区工作室分润比例小于0.00")
    @DecimalMax(value = "1.00", message = "社区工作室分润比例大于1.00")
    private BigDecimal communityStudioIncome;

    @ApiModelProperty(value = "NONO商城收益比例")
    @NotNull(message = "请输入NONO商城收益比例！")
    @DecimalMin(value = "0.00", message = "NONO商城分润比例小于0.00")
    @DecimalMax(value = "1.00", message = "NONO商城分润比例大于1.00")
    private BigDecimal mallIncome;

    @ApiModelProperty(value = "玛特收益比例")
    @NotNull(message = "请输入玛特收益比例！")
    @DecimalMin(value = "0.00", message = "玛特分润比例小于0.00")
    @DecimalMax(value = "1.00", message = "玛特分润比例大于1.00")
    private BigDecimal metaIncome;

    @ApiModelProperty(value = "玛特收益daoId")
    @NotNull(message = "请输入玛特收益daoId！")
    private Long metaIncomeDaoId;

    @ApiModelProperty(value = "瓜分分润比例")
    @NotNull(message = "请输入瓜分分润比例！")
    @DecimalMin(value = "0.00", message = "瓜分分润比例小于0.00")
    @DecimalMax(value = "1.00", message = "瓜分分润比例大于1.00")
    private BigDecimal carveUpRatio;

    @ApiModelProperty(value = "排行榜分润比例")
    @NotNull(message = "请输入排行榜分润比例！")
    @DecimalMin(value = "0.00", message = "排行榜分润比例小于0.00")
    @DecimalMax(value = "1.00", message = "排行榜分润比例大于1.00")
    private BigDecimal rankingListRatio;

    @ApiModelProperty(value = "生态商品收益比例")
    @NotNull(message = "请输入生态商品收益比例！")
    @DecimalMin(value = "0.00", message = "生态商品分润比例小于0.00")
    @DecimalMax(value = "1.00", message = "生态商品分润比例大于1.00")
    private BigDecimal ecologicalCommodityIncome;

    @ApiModelProperty(value = "生态商品收益daoId")
    @NotNull(message = "请输入生态商品收益daoId！")
    private Long ecologicalCommodityIncomeDaoId;

    @ApiModelProperty(value = "购买人网体所属DAO分润比例")
    @NotNull(message = "请输入购买人网体所属DAO分润比例！")
    @DecimalMin(value = "0.00", message = "购买人网体所属DAO分润比例小于0.00")
    @DecimalMax(value = "1.00", message = "购买人网体所属DAO分润比例大于1.00")
    private BigDecimal purchaserDaoRatio;

    @ApiModelProperty(value = "平台收益比例")
    @NotNull(message = "请输入平台收益比例！")
    @DecimalMin(value = "0.00", message = "平台收益分润比例小于0.00")
    @DecimalMax(value = "1.00", message = "平台收益分润比例大于1.00")
    private BigDecimal ecologicalCommodityIncomeDaoRatio;

    /**
     * 编辑分润模版参数校验
     */
    public void check() {
        if (BigDecimalUtils.compare(BigDecimal.ZERO, directIncome) || BigDecimalUtils.compare(BigDecimal.ZERO, supplierReferrerIncome)
                || BigDecimalUtils.compare(BigDecimal.ZERO, mapIncome)
                || BigDecimalUtils.compare(BigDecimal.ZERO, urbanServiceCenterIncome)
                || BigDecimalUtils.compare(BigDecimal.ZERO, communityStudioIncome) || BigDecimalUtils.compare(BigDecimal.ZERO, mallIncome)
                || BigDecimalUtils.compare(BigDecimal.ZERO, metaIncome) || BigDecimalUtils.compare(BigDecimal.ZERO, ecologicalCommodityIncome)
                || BigDecimalUtils.compare(BigDecimal.ZERO, carveUpRatio) || BigDecimalUtils.compare(BigDecimal.ZERO, rankingListRatio)
                || BigDecimalUtils.compare(BigDecimal.ZERO, purchaserDaoRatio) || BigDecimalUtils.compare(BigDecimal.ZERO, ecologicalCommodityIncomeDaoRatio)) {
            throw new GlobalRunTimeException("分润比例不得小于0");
        }

        // 总分润比例
        BigDecimal ratio = BigDecimalUtils.add(directIncome, supplierReferrerIncome, mapIncome,  urbanServiceCenterIncome, communityStudioIncome, mallIncome, metaIncome, ecologicalCommodityIncome);
        if (!BigDecimalUtils.eq(ratio, 1)) {
            throw new GlobalRunTimeException("总分润比例必须为百分百");
        }

        // 玛特分润比例
        BigDecimal metaRatio = BigDecimalUtils.add(carveUpRatio, rankingListRatio);
        if (!BigDecimalUtils.compareTo(1, metaRatio)) {
            throw new GlobalRunTimeException("玛特子级分润比例不得大于100%");
        }

        // 生态分润比例
        BigDecimal zoologyRatio = BigDecimalUtils.add(purchaserDaoRatio, ecologicalCommodityIncomeDaoRatio);
        if (!BigDecimalUtils.eq(zoologyRatio, 1)) {
            throw new GlobalRunTimeException("生态子级分润比例必须为100%");
        }
    }

}
